package models;

import helpers.GeneralHelper;
import helpers.SettingHelper;

import java.util.ArrayList;
import java.util.List;

import javax.cache.Cache;

import com.google.appengine.api.NamespaceManager;
import com.googlecode.objectify.Key;
import com.googlecode.objectify.Objectify;
import com.googlecode.objectify.ObjectifyService;

import entities.ApplicationMapping;

public class ApplicationMappingModel {
	private Objectify ofy;
	
	private Cache cache = null;
	
	private String cachePrefix = "application_mapping_";
	
	private static ApplicationMappingModel instance = null;
	
	public static ApplicationMappingModel getInstance() {
		if (instance == null) {
			instance = new ApplicationMappingModel();
		}
		
		return instance;
	}
	
	private ApplicationMappingModel() {
		try {
			ObjectifyService.register(ApplicationMapping.class);
		} catch (Exception e) {
			//e.printStackTrace();
		}
		
		cache = GeneralHelper.getCache();
		ofy = GeneralHelper.getObjectify();
	}
	
	public ApplicationMapping get(String id) {
		NamespaceManager.set(SettingHelper.getGeneralNamespace());
		
		ApplicationMapping appMapping = new ApplicationMapping();
		
		try {
			appMapping = ofy.get(new Key<ApplicationMapping>(ApplicationMapping.class, id));
		} catch (Exception e) {
			appMapping = null;
		}
		
		return appMapping;
	}
}
